package com.amsp.oa.oademo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.amsp.oa.oademo.entity.EmployeeResignation;
import com.amsp.oa.oademo.mapper.EmployeeResignationMapper;
import com.amsp.oa.oademo.service.EmployeeResignationService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class EmployeeResignationServiceImpl extends ServiceImpl<EmployeeResignationMapper, EmployeeResignation>
        implements EmployeeResignationService {

    @Override
    public IPage<EmployeeResignation> getPage(Integer current, Integer size, String empName, String empDepartment) {
        LambdaQueryWrapper<EmployeeResignation> wrapper = new LambdaQueryWrapper<>();

        if (StringUtils.hasText(empName)) {
            wrapper.like(EmployeeResignation::getEmpName, empName);
        }

        if (StringUtils.hasText(empDepartment)) {
            wrapper.like(EmployeeResignation::getEmpDepartment, empDepartment);
        }

        wrapper.orderByDesc(EmployeeResignation::getCreateTime);
        Page<EmployeeResignation> page = page(new Page<>(current, size), wrapper);
        return page;
    }
}